import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
import org.junit.Test;


public class MyTest {
	
	String original = "风急天萧猿啸哀";

	@Test
	public void testBase64(){
		
		Base64 base64 = new Base64();
		byte[] encode = base64.encode(original.getBytes()); //编码
		byte[] decode = base64.decode(encode); //解码
		
		System.out.println(new String(encode));
		System.out.println(new String(decode));
	}
	
	@Test
	public void testBase64_2(){
		
		byte[] encode = Base64.encodeBase64(original.getBytes()); //编码
		byte[] decode = Base64.decodeBase64(encode); //解码
		
		System.out.println(new String(encode));
		System.out.println(new String(decode));
	}
	
	@Test
	public void testHex() throws DecoderException{
		
		Hex hex = new Hex();
		
		byte[] encode = hex.encode(original.getBytes()); //编码
		byte[] decode = hex.decode(encode); //解码
		
		System.out.println(new String(encode));
		System.out.println(new String(decode));
	}
	
	@Test
	public void testHex_2() throws DecoderException{
		
		char[] encode = Hex.encodeHex(original.getBytes()); //编码
		byte[] decode = Hex.decodeHex(encode); //解码
		
		System.out.println(new String(encode));
		System.out.println(new String(decode));
	}
	
	@Test
	public void testMD5(){
		
		System.out.println(DigestUtils.md5Hex("tuyou"));
	}
}
